﻿using System.Configuration;

namespace ManagedUIFlow.Infrastructure.Flows.Configuration
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1010:CollectionsShouldImplementGenericInterface")]
    public class GivenConfigurationElementCollection : ConfigurationElementCollection
    {              
        [ConfigurationProperty("that", IsRequired = false)]
        public string Name
        {
            get { return (string)base["that"]; }
            set { base["that"] = value; }
        }       

        protected override bool ThrowOnDuplicate
        {
            get { return true; }
        }

        public void Add(WhenConfigurationElement switchNode)
        {
            BaseAdd(switchNode);
        }

        public bool Contains(string switchNode)
        {
            return base.BaseGet(switchNode) != null;
        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get { return ConfigurationElementCollectionType.BasicMap; }
        }

        protected override string ElementName
        {
            get { return "when"; }
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new WhenConfigurationElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((WhenConfigurationElement)element).NavigateTo ?? "default";
        }

        public WhenConfigurationElement this[int index]
        {
            get { return (WhenConfigurationElement)base.BaseGet(index); }
        }
    }
}